#
rm(list=ls(all=TRUE))
#
library(MASS)
library(foreign)
library(readxl)

#
#
T <- read_excel("ordinal_parties.xlsx")
attach(T,warn.conflicts = FALSE)

#
T <- cbind(mean,lower,upper)
mode(T) <- "double"
T<- T[9:16,]
#colnames(TT) <- c("name","mean","lower","upper")
name <-cbind(party)
name1<- name[9:16,]
#
#T <- as.matrix(T)
#
#names <- TT[,1]
mean1 <- T[,1]
lower1 <- T[,2]
upper1 <- T[,3]
# 
TT <- cbind(mean,lower,upper)
mode(TT) <- "double"
TT<- TT[1:8,]
#colnames(TT) <- c("name","mean","lower","upper")
name <-cbind(party)
name2<- name[1:8,]
#
#T <- as.matrix(T)
#
#names <- TT[,1]
mean2 <- TT[,1]
lower2 <- TT[,2]
upper2 <- TT[,3]
#
y.axis <- c(length(mean2):1)
#
adjust <- 0 #create object that we will use to adjust points and lines up and down to distinguish between models
#
par(mfrow=c(1,2))
#
par(mar=c(2, 10, 2, 2))#set margins for plot, leaving lots of room on left-margin (2nd number in margin command) for variable names
plot(mean2, y.axis+adjust, type = "p", axes = F, xlab = "", ylab = "", pch = 19, cex = .75, xlim = c(-3.6,3.6), xaxs = "r", main = "Legislators' Ideal Points (Government-Opposition)") 
segments(lower2, y.axis+adjust, upper2, y.axis+adjust, lwd =  1.5)
axis(1, at = seq(-3.6,3.6,by=1), labels = NA, tick = T,#draw x-axis and labels with tick marks
    cex.axis = .75, mgp = c(2,.7,0))#reduce label size, moves labels closer to tick marks
axis(1, at = seq(-3,3,by=1), labels =  c(-3, -2, -1, 0, 1, 2, 3), tick = T,#draw x-axis and labels with tick marks
    cex.axis = .75, mgp = c(2,.7,0))
axis(2, at = y.axis+adjust, label = name2, las = 1, tick = T, ,mgp = c(2,.6,0),
    cex.axis = .75) #draw y-axis with tick marks, make labels perpendicular to axis and closer to axis
#segments(-.427,-.427,-.427,8,lty=2) # draw dotted line through 0
abline(v=0, lty = 2)
#
y.axis <- c(length(mean1):1)
#
adjust <- 0 #create object that we will use to adjust points and lines up and down to distinguish between models
#
#
par(mar=c(2, 10, 2, 2))#set margins for plot, leaving lots of room on left-margin (2nd number in margin command) for variable names
plot(mean1, y.axis+adjust, type = "p", axes = F, xlab = "", ylab = "", pch = 19, cex = .75, xlim = c(-3.6,3.6), xaxs = "r", main = "Voters' Ideological Location (Left-Right)") 
segments(lower1, y.axis+adjust, upper1, y.axis+adjust, lwd =  1.5)
axis(1, at = seq(-3.6,3.6,by=1), labels = NA, tick = T,#draw x-axis and labels with tick marks
    cex.axis = .75, mgp = c(2,.7,0))#reduce label size, moves labels closer to tick marks
axis(1, at = seq(-3,3,by=1), labels =  c(-3, -2, -1, 0, 1, 2, 3), tick = T,#draw x-axis and labels with tick marks
    cex.axis = .75, mgp = c(2,.7,0))
axis(2, at = y.axis+adjust, label = name1, las = 1, tick = T, ,mgp = c(2,.6,0),
    cex.axis = .75) #draw y-axis with tick marks, make labels perpendicular to axis and closer to axis
#segments(-.427,-.427,-.427,8,lty=2) # draw dotted line through 0
abline(v=0, lty = 2)


